package com.authorization.authorizationserveronsso.utils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class DataBus {
    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "返回码")
    private String code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();

    private DataBus(){}

    public static DataBus success(){
        DataBus dataBus = new DataBus();
        dataBus.setCode(ResultCode.SUCCESS);
        dataBus.setSuccess(true);
        dataBus.setMessage("成功");
        return dataBus;
    }

    public static DataBus error(){
        DataBus dataBus = new DataBus();
        dataBus.setCode(ResultCode.ERROR);
        dataBus.setSuccess(false);
        dataBus.setMessage("失败");
        return dataBus;
    }

    public DataBus code(String code) {
        this.setCode(code);
        return this;
    }

    public DataBus success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public DataBus message(String message){
        this.setMessage(message);
        return this;
    }

    public DataBus data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public DataBus data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
